local panel_list = {}

class.clicked_panel = extends(class.panel) {
    
    select_w = 64,
    select_h = 64,
    select_gap = 10,
    is_vertical = false,    --竖立显示
    count = 3,
    init = function (self)
        class.panel.init(self)
        
        local x,y = self.x,self.y
        if not self.select_x then
            if self.is_vertical then
                self.select_x = (self.w - self.select_w)/2
            else
                self.select_x = (self.w - (self.select_w + self.select_gap)*self.count + self.select_gap)/2
            end
        end
        if not self.select_y then
            if not self.is_vertical then
                self.select_y = (self.h - self.select_w)/2
            else
                self.select_y = (self.h - (self.select_w + self.select_gap)*self.count + self.select_gap)/2
            end
        end

        self.buttons = {}
        for i = 1, self.count do 
            local button = self:add_button('1',self.select_x,self.select_y,self.select_w,self.select_h,1)
            button.index = i
            self.buttons[i] = button
            if self.is_vertical then
                self.select_y = self.select_y + self.select_h + self.select_gap
            else
                self.select_x = self.select_x + self.select_w + self.select_gap
            end
        end

        panel_list[self] = true

        return self
    end,
    new = function (parent,image_path,x,y,width,height)
        local panel = class.clicked_panel:builder 
        {
            parent = parent,
            x = x,
            y = y,
            w = width,
            h = height,
        }
        return panel
    end,
    update = function(self)
        
    end,
    set_data = function(self,data)
        for a,button in ipairs(self.buttons) do
            local skill = data[a]
            button.skill = skill
            if skill then
                button:set_normal_image(skill.art)
            end
        end
    end,
    on_button_mouse_enter = function(self,button)
        local skill = button.skill
        if skill then
            local tip = skill:get_tip()
            button:tooltip(skill.title or skill.name,tip,'top')
        end
    end,
    on_button_clicked = function (self, button)
        if button.index and button.skill then 
            ac.sync(self.sync_name or self.name,button.index)
        end 
    end,
}



ac.hardware:event '界面绘制'(function()
    for panel in pairs(panel_list) do
        panel:update()
    end
end)